import { ChannelItem } from "@/types/data"
import { ChannelAction } from "@/types/store"

interface IState  {
  channels: ChannelItem[]
  active: number
}

const initState: IState = {
  channels: [],
  active: 0
}

export default function channel(preState = initState, aciton: ChannelAction): IState {
  switch (aciton.type) {
    case 'CHANNEL_SAVE':
      return {
        ...preState,
        channels: aciton.payload,
        active: aciton.payload[0].id
      }
    case 'CHANNEL_ACTIVE':
      return {
        ...preState,
        active: aciton.payload
      }

    default:
      return preState
  }

}